package org.apache.flink.runtime.cleanup;

import org.apache.flink.api.common.ConsumerID;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

/**
 * {@code GloballyCleanableResource} is supposed to be implemented by any class that provides
 * artifacts for a given job that need to be cleaned up after the job reached a global terminal
 * state.
 *
 * @see LocallyCleanableResource
 * @see org.apache.flink.api.common.ConsumingStatus
 */
@FunctionalInterface
public interface GloballyCleanableResource {

    /**
     * {@code globalCleanupAsync} is expected to be called from the main thread. Heavy IO tasks
     * should be outsourced into the passed {@code cleanupExecutor}. Thread-safety must be ensured.
     *
     * @param jobId The {@link ConsumerID} of the job for which the local data should be cleaned up.
     * @param cleanupExecutor The fallback executor for IO-heavy operations.
     * @return The cleanup result future.
     */
    CompletableFuture<Void> globalCleanupAsync(ConsumerID jobId, Executor cleanupExecutor);
}
